package com.ybzl.quartz.config;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.InfluxDBClientOptions;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;

public class InfluxFactory extends BasePooledObjectFactory<InfluxConn> {

    private String url;

    private String token;

    private String org;

    public InfluxFactory( String url, String token,String org) {
        this.url = url;
        this.token = token;
        this.org =  org;
    }

    @Override
    public InfluxConn create() throws Exception {
        InfluxConn influxConn = new InfluxConn();
        InfluxDBClient client = InfluxDBClientFactory.create(url, token.toCharArray(),org);


        influxConn.setInfluxDB(client);
        return influxConn;

    }

    @Override
    public PooledObject<InfluxConn> wrap(InfluxConn influxConn) {
        return new DefaultPooledObject(influxConn);
    }
}
